package com.tyd.cams;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tyd.cams.Adapter.ClassRecyclerAdapter;
import com.tyd.cams.Adapter.FanKanRecyclerAdapter;
import com.tyd.cams.entity.ClassInfobean;
import com.tyd.cams.entity.FanKabean;
import com.tyd.cams.utils.SPUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import okhttp3.Call;

import static com.xuexiang.xui.XUI.getContext;

public class ClassManageActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    ClassRecyclerAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_class_manage);
        getClassList();
    }
    private void getClassList() {
        new Thread(() -> OkHttpUtils.post()
                .url(SPUtils.getIP() + "/getTable")
                .addHeader("Authorization", SPUtils.getToken())
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ClassManageActivity.this, "班级查询链接服务器超时", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.i("获取的返回信息", response);
                        Gson son = new Gson();
                        List<ClassInfobean> classInfobeans = son.fromJson(response, new TypeToken<List<ClassInfobean>>() {
                        }.getType());
                        Log.i("班级", classInfobeans.toString());
                        //设置适配器
                        recyclerView = findViewById(R.id.class_recycleview);
                        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
                        adapter = new ClassRecyclerAdapter(ClassManageActivity.this, classInfobeans);
                        recyclerView.setLayoutManager(new LinearLayoutManager(ClassManageActivity.this, LinearLayoutManager.VERTICAL, false));
                        recyclerView.setAdapter(adapter);
                    }
                })).start();

    }

}